|
|
@@ -64,20 +64,24 @@ class Service < ActiveRecord::Base
|
64
|
64
|
|
65
|
65
|
def self.provider_specific_options(omniauth)
|
66
|
66
|
case omniauth['provider']
|
|
67
|
+ when 'twitter', 'github'
|
|
68
|
+ { name: omniauth['info']['nickname'] }
|
67
|
69
|
when '37signals'
|
68
|
|
- { user_id: omniauth['extra']['accounts'][0]['id'] }
|
|
70
|
+ { user_id: omniauth['extra']['accounts'][0]['id'], name: omniauth['info']['name'] }
|
69
|
71
|
else
|
70
|
|
- {}
|
|
72
|
+ { name: omniauth['info']['nickname'] }
|
71
|
73
|
end
|
72
|
74
|
end
|
73
|
75
|
|
74
|
76
|
def self.initialize_or_update_via_omniauth(omniauth)
|
75
|
|
- find_or_initialize_by(provider: omniauth['provider'], name: omniauth['info']['nickname'] || omniauth['info']['name']).tap do |service|
|
|
77
|
+ options = provider_specific_options(omniauth)
|
|
78
|
+
|
|
79
|
+ find_or_initialize_by(provider: omniauth['provider'], name: options[:name]).tap do |service|
|
76
|
80
|
service.assign_attributes token: omniauth['credentials']['token'],
|
77
|
81
|
secret: omniauth['credentials']['secret'],
|
78
|
82
|
refresh_token: omniauth['credentials']['refresh_token'],
|
79
|
83
|
expires_at: omniauth['credentials']['expires_at'] && Time.at(omniauth['credentials']['expires_at']),
|
80
|
|
- options: provider_specific_options(omniauth)
|
|
84
|
+ options: options
|
81
|
85
|
end
|
82
|
86
|
end
|
83
|
87
|
end
|